﻿using System;

namespace TLD_NN
{
    /// <summary>
    /// Neuron object, currently only output-neurons supported
    /// </summary>
    public class Neuron
    {
        public double[] Weights { get; private set; }

        /// <summary>
        /// Creates a neuron with weights to which input can be mapped.
        /// </summary>
        /// <param name="numWeights">number of connections to this neuron</param>
        public Neuron(int numWeights)
        {
            Weights = new double[numWeights];
        }

        /// <summary>
        /// Returns the distance between input and weights squared and summated
        /// </summary>
        /// <param name="input">normalized input array</param>
        /// <returns>sum of squared distances between input and weights</returns>
        public double GetDistanceSquared(double[] input)
        {
            double sum = 0;
            for (int i = 0; i < Weights.Length; i++)
            {
                double dist = input[i] - Weights[i];
                sum += dist * dist;
            }

            return sum;
        }

        /// <summary>
        /// Calculates the euclidean distance using GetDistanceSquared 
        /// </summary>
        /// <param name="input">normalized input array</param>
        /// <returns>euclidean distance between input and weights</returns>
        public double GetDistance(double[] input)
        {
            return Math.Sqrt(GetDistanceSquared(input));
        }
    }
}
